
*Sorting IRS County Migration Data*
import excel using "county_migration_data.xlsx", firstrow clear
foreach var of varlist _all {
local label : variable label `var'
local new_name = lower(strtoname("`label'"))
rename `var' `new_name'
}
rename (_*) (m*)

drop if origin==destination

preserve
	drop destination
	collapse (sum) m1990-m2010, by(origin)
	rename origin countyfip
	reshape long m, i(countyfip) j(year)
	rename m outmig
	tempfile cntyoutmig
	save `cntyoutmig'
restore

drop origin
collapse (sum) m1990-m2010, by(destination)
rename destination countyfip
reshape long m, i(countyfip) j(year)
rename m inmig
xtset countyfip year

joinby countyfip year using `cntyoutmig', unmatched(master)
tab _merge
drop _merge

gen netmig=inmig-outmig

save cntynetmig.dta, replace
